using Digitalmes.Application.Mes.Productions.Products.Commands;
using Digitalmes.Application.Mes.Productions.Products.Queries;

namespace Digitalmes.WebApi.Endpoints.Mes.Productions;

/// <summary>
/// 生产状态终结点
/// </summary>
public sealed class ProductStateEndpoint : EndpointGroupBase
{
    public override void Map(WebApplication app)
    {
        app.MapGroup(this, "mes/production", "productState")
            .RequireAuthorization()
            .MapGet(GetProductPagedListAsync, "list-page")
            .MapPut(ConcedeProductAsync, "concede")
            .MapPut(UnfitProductAsync, "unfit")
            .MapPut(ScrapProductAsync, "scrap");
    }

    [EndpointDescription("分页获取产品生产信息，模糊查询")]
    public async Task<IApiResult> GetProductPagedListAsync(ISender sender, [AsParameters] GetProductListWithPagedQuery query)
    {
        var result = await sender.Send(query);
        return result.ToApiResult();
    }

    [EndpointDescription("产品让步接收")]
    public async Task<IApiResult> ConcedeProductAsync(ISender sender, ConcedeProductCommand command)
    {
        var result = await sender.Send(command);
        return result.ToApiResult();
    }

    [EndpointDescription("产品强制不合格")]
    public async Task<IApiResult> UnfitProductAsync(ISender sender, UnfitProductCommand command)
    {
        var result = await sender.Send(command);
        return result.ToApiResult();
    }

    [EndpointDescription("产品强制报废")]
    public async Task<IApiResult> ScrapProductAsync(ISender sender, ScrapProductCommand command)
    {
        var result = await sender.Send(command);
        return result.ToApiResult();
    }
}
